<!-- DJ -->
<script type="text/javascript">
<!--
var catid = '{$catid}';
var marca_cargada = 0;
var marcaMotor_cargada = 0;
var const_elija = '<option value=""> --- Seleccione --- </option>';
{literal}
	//jQuery(function() {configMarca();});

jQuery(document).ready(function(){
		configMarca();
		//configMarcaMotor();
		//configModelo();
		setupLocalidad();
	});

function configMarca() {
	    marca_cargada  = 1;
		if(marca_cargada  == 0){
				jQuery.get("search_autoCompleter.php?action=marcaAltaArt&cat_id="+catid+"&selected="+jQuery("#hidden_id_ef_marca_mt").val(),{},function(data){
					jQuery(".ef_marca_mt").html(const_elija + data);			
				});
				marca_cargada  = 1;
			}
		
		if(jQuery(".ef_marca_mt").val()=={/literal}{$smarty.const.MV_OTHER_BRAND}{literal}){
			jQuery('#divOtraMarca').css({"display" : ""});
			if(jQuery("#hidden_id_ef_marca_mt").val()!='' && jQuery("#hidden_id_ef_marca_mt").val()!='330'){
				jQuery('#otraMarca').attr("value", jQuery("#hidden_id_ef_marca_mt").val());
			}		
		}
}

function configMarcaMotor() {
		jQuery(".ef_marca_motor_mt").click(function(){
			if(marcaMotor_cargada  == 0){
				jQuery.get("search_autoCompleter.php?action=marcaAltaArt&cat_id="+catid,{},function(data){
					jQuery(".ef_marca_motor_mt").html(const_elija + data);			
				});
				marcaMotor_cargada = 1;
			}
		 }); 
}

function configModelo()
{
		jQuery(".ef_marca_mt").change(function(){			
			jQuery.get("search_autoCompleter.php?action=modeloAltaArt&marca_id="+jQuery(".ef_marca_mt").val(),{},function(data){
				jQuery(".ef_modelo_mt").html(const_elija + data);			
			});
		 }); 
}

function setupAutocomplete() {
	jQuery(".ef_marca_mt").autocomplete("search_autoCompleter.php?action=marcaJson&cat_id="+catid, {
		minChars: 0, max: 12, autoFill: false, 
		selectFirst: false, mustMatch: false,
		matchContains: true, scrollHeight: 220,
		parse: function(data){
			var map = $.map(eval(data), function(row) {return { data: row, value: row.marca, result: row.marca }});
			return map;
		},
		formatItem: function(data, i, total) {
			return  i + ") " + data.marca;
		}
	}).result(function(e, item)	{
		$("#marca_id").val(item.id);
		$("#modelo_id").val('');
		$(".ef_modelo_mt").val('');		
	});
	
	//MODELO
	jQuery(".ef_modelo_mt").autocomplete("search_autoCompleter.php?action=modeloJson", {
		minChars: 0, max: 12, autoFill: true, 
		selectFirst: true, mustMatch: false,
		matchContains: true, scrollHeight: 220,
		extraParams: {'tipo': catid, 'marca': function() { return $("#marca_id").val();}},
		parse: function(data){
			var map = $.map(eval(data), function(row) {return { data: row, value: row.modelo, result: row.modelo }});
			return map;
		},
		formatItem: function(data, i, total) {
			return  data.modelo;
		}
	}).result(function(e, item)	{
		$("#modelo_id").val(item.id);
	});;	
	
	/*
	var button = jQuery('<a>&nbsp;Mostrar</a>');
	var elem = jQuery(".ef_marca_mt").get(0);
	
	jQuery(button).mouseup(function(){
		var event = jQuery.Event("keydown");
		event.keyCode = 40; //DOWN
		var aux = jQuery(elem).val();
		jQuery(elem).focus().val("").trigger(event).val(aux);
	});

	jQuery(button).insertAfter(".ef_marca_mt, .ef_modelo_mt");
	*/
	
	//ponerBotonMostrar(".ef_marca_mt");
	//ponerBotonMostrar(".ef_modelo_mt");

}

function ponerBotonMostrar(selector){
	var button = jQuery('<a>&nbsp;Mostrar</a>');
	var elem = jQuery(selector).get(0);
	
	jQuery(button).mouseup(function(){
		var event = jQuery.Event("keydown");
		event.keyCode = 40; //DOWN
		var aux = jQuery(elem).val();
		jQuery(elem).focus().val("").trigger(event).val(aux);
	});
	
	jQuery(button).insertAfter(selector);
}

function setupLocalidad(){
	jQuery("#localidad").autocomplete("search_autoCompleter.php?action=localidadJson", {
		minChars: 1, max: 20, autoFill: false, 
		selectFirst: true, mustMatch: false,
		matchContains: true, scrollHeight: 220,
		extraParams: { provincia: function() { return jQuery("#provincia").val();}},
		parse: parseLocalidades,
		formatItem: formatItemLocalidad
	}).result(function(e, item)	{
		//alert(item.id);
		jQuery("#localidad").val(item.localidad_full).attr("readonly",true);
		jQuery("#localidad_id").val(item.id);
	});		
}

function cleanLocalidad(){
	jQuery('#localidad').val('').removeAttr('readonly').focus();
	jQuery("#localidad_id").val('');
}

function showEditable($val){
	
	if($val=={/literal}{$smarty.const.MV_OTHER_BRAND}{literal}){
		jQuery('#divOtraMarca').css({"display" : ""});
	}else{
		jQuery('#divOtraMarca').css({"display" : "none"});
		jQuery('#otraMarca').attr("value", "");		
	}
}
//-->
</script>
{/literal}

{if !$submit_ok}
	<h5 class="memberarea_caption">{$catname}</h5>
{/if}
<script language="javascript">
xajax_myFunction('{$reg_2_value}');
xajax_myFunction('{$reg_3_value}');
</script> 
<table border="0" cellspacing="1" width="100%">
<tr>
    <td width="100%" valign="top">


{if $errorMsg}
	<div class="error_messages_list">
		<h3>{$smarty.const.EF_ERROR_ITEM}</h3>
		<ol class="error_messages_list">{$errorMsg}</ol>
	</div>
	
{/if}

{if $submit_ok}

	{if $await_validation}
	<p>{$smarty.const.LA_VALIDATION_WAIT}</p>
	{/if}

<h5 class="memberarea_caption">{$smarty.const.LA_CHOOSE}</h5>
<div style="clear:both;height:12px;"></div>
	{if $url_to_bold}
	<br />
	<a href='{$url_to_bold}?ad_id={$ad_id}' class="thumb">
	<img src="{$url}/layout_images/new/bold2.gif" align="left" border="0" hspace="3" vspace="3" alt="{$smarty.const.LA_MEMBER_EXTRA}" />
	</a>
	<a href='{$url_to_bold}?ad_id={$ad_id}'>{$smarty.const.LA_MEMBER_EXTRA}</a>
	{/if}
	{if $picture_upload_enable}
	<br /><br />
	<a href='{$url_to_upload}?pic_ad_id={$ad_id}' class="thumb">
	<img src="{$url}/layout_images/new/images.gif" align="left" border="0" hspace="3" vspace="3" alt="{$smarty.const.LA_UPLOAD_VIDEO}" />
	</a>
	<a href='{$url_to_upload}?pic_ad_id={$ad_id}'>{$smarty.const.LA_I_WANT}</a>
	{/if}	
	
	{if $set_video_upload}
	<br /><br />
	<a href='{$url_to_upload_video}?video_ad_id={$ad_id}' class="thumb">
	<img src="{$url}/layout_images/new/film.gif" align="left" border="0" hspace="3" vspace="3" alt="{$smarty.const.LA_UPLOAD_VIDEO}" />
	</a>
	<a href='{$url_to_upload_video}?video_ad_id={$ad_id}'>
	{$smarty.const.LA_UPLOAD_VIDEO}</a>
	{/if}
	
	{if $set_doc_upload}
	<br /><br />
	<a href='{$url_to_upload_doc}?doc_ad_id={$ad_id}' class="thumb">
	<img src="{$url}/layout_images/new/doc.gif" align="left" border="0" hspace="3" vspace="3" alt="{$smarty.const.LA_UPLOAD_DOC}" />
	</a>
	<a href='{$url_to_upload_doc}?doc_ad_id={$ad_id}'>
	{$smarty.const.LA_UPLOAD_DOC}</a>
	{/if}
	
	<br /><br />
	<a href='index.php' class="thumb">
	<img src="{$url}/layout_images/new/home_icon.gif" align="left" border="0" hspace="3" vspace="3" alt="{$smarty.const.LA_RET}" />
	</a><a href='index.php'>{$smarty.const.LA_RET}</a>
    <br /><br />
    <a href='choose_cat.php' class="thumb">
	<img src="{$url}/layout_images/new/addad.gif" align="left" border="0" hspace="3" vspace="3" alt="{$smarty.const.LA_ADD_AN}" />
	</a>
    <a href='choose_cat.php'>{$smarty.const.LA_ADD_AN}</a>
    <br />

{/if}

{if $pay_out_of_credits}
	<h4>{$smarty.const.LA_OUT_OF_CREDITS}</h4>
	{$smarty.const.LA_CREDITS_WARNING} <br />
	{$smarty.const.LA_CREDITS_WARNING2}
	<br /><br />{$smarty.const.LA_VISIT_OUR} <a href="payment_options.php?catid={$catid}"><u>{$smarty.const.LA_PAID_MEMBERSHIP}</u></a> {$smarty.const.LA_FOR_MORE_INFO}<br /><br />		
{/if}

{if $show_form}

{if $set_payments}
	<p style="background-color:white">	
		{$smarty.const.LA_PAY_CREDITS_BAL}<b>{$pay_free_credits}</b> {$smarty.const.EF_PAY_AVISOS}
	{if $have_an_order}
		{$smarty.const.EF_ORDER_PENDIENTE}
	{/if}
	<br />
	{*{$smarty.const.LA_PAY_COST} <b>{$pay_catcost}</b> {$smarty.const.LA_PAY_CREDITS}*}
	</p>
	<div style="clear:both;height:12px;"></div>
{/if}

<form method='post' action='{$phpself}' name="itemForm">
	<input type='hidden' name='ad_id' value='{$ad_id}'>
	<input type='hidden' name='update_rq' value='{$update_rq}'>
{if !$ad_id}
	<input type='hidden' name='catid' id='catid' value='{$catid}'>
{/if}

<input type='hidden' name='marca_id' id='marca_id' value=''>
<input type='hidden' name='modelo_id' id='modelo_id' value=''>

<table border="0" cellpadding="4" width="100%" class="tabla_edicion_item">
	{if $paquetes }
	<tr>
	<td width="30%" valign="top" align="right" style="padding-right: 5px;">{$smarty.const.EF_AVISO_TYPE}</td>
	<td><select name="packageId" id="packageId" class="regionselect">
		{foreach item=pa from=$paquetes}
			<option value="{$pa.pid}" {if $PackageId && $PackageId==$pa.pid}selected="selected"{/if}>{$pa.pname}</option>
		{/foreach}
		</select>
	</td>
	</tr>
	{/if}
	<tr>
    <td width="30%" valign="top" align="right" style="padding-right: 5px;">{$smarty.const.TITLE} <span class="red">*</span></td>
    <td width="70%" valign="top">
	<input type="text" name="ad_title" size="39" maxlength="150" class="txt" value="{$ad_title}">
	</td>
  	</tr>

  	{if $set_region==1 && !$admin_region_options}
		<tr>
	    <td width="30%" valign="top">{$smarty.const.LA_REGION} <span class="red">*</span></td>
	    <td width="70%" valign="top">
		<select id="reg_1" name="reg_1" onChange='xajax_myFunction(reg_1.value)' class='regionselect'>
		{$reg_1_options}
		</select>
		
		<p><div id="DropDown2"></div></p>
		<p><div id="DropDown3"></div></p>
		
		</td>
	  	</tr>
  	{elseif $admin_region_options}
  		<tr>
	    <td width="30%" valign="top">{$smarty.const.LA_REGION} <span class="red">*</span></td>
	    <td width="70%" valign="top">
		<select id="admin_region_selected" name="admin_region_selected" class='regionselect'>
		{$admin_region_options}
		</select>
		</td>
	  	</tr>
  	
  	{/if}
  	
	
	<!-- DESCRIPTCION -->
  <tr>
    <td width="30%" valign="top" align="right" style="padding-right: 5px;">
		{$smarty.const.DESCRIPTION} <span class="red">*</span>
	</td>
    <td width="70%" valign="top">
		<textarea rows="7" id="ad_description" name="ad_description" cols="45">{$ad_description}</textarea>
    </td>
  </tr>
  

  <!-- PRECIO -->
  <tr>
    <td width="30%" valign="top" align="right" style="padding-right: 5px;">
		Precio</span><span class="red">*</span>
	</td>
    <td width="70%" valign="top">
		<input type="text" name="precio" id="precio" size="10" value="{$ad_precio}" />
		<select name="moneda" id="moneda">
			{$ad_moneda_options}
		</select>
		{$smarty.const.NO_INCLUYE}
    </td>
  </tr> 

<!-- OTROS CAMPOS -->  
{foreach item=e from=$extra_fields_array}

{if $e.q_catdescr}
	<tr><td colspan="2">
   		<b>{$e.q_catdescr}</b><hr style="color:black;" width="50%" align="left">
	</td></tr>
{/if}

<tr>
	<td valign="top" align="right" style="padding-right: 5px;">{$e.q_question} {if $e.q_mand}<span class="red">*</span>{/if}</td>
   	<td valign="top">
   	
   	{if $e.q_type=="t"}

   		<input type="text" name="e_{$e.q_field}" size="{$e.q_size}" value="{$e.q_value}" class="{$e.q_css_class}"/>

   	{elseif $e.q_type=="e"}

   		<input type="text" name="e_{$e.q_field}" size="{$e.q_size}" value="{$e.q_value}" class="{$e.q_css_class}" />
	
	{elseif $e.q_type=="a"}
		<input type="hidden" value="{$e.q_value}" id="hidden_id_{$e.q_css_class}"/>
   		<select name="e_{$e.q_field}" id="id_{$e.q_field}" class="{$e.q_css_class}" onchange="javascript: showEditable(this.options[this.selectedIndex].value);" >
   			<option value=""> --- Seleccione --- </option>
   			{$marcasPorCat}
		</select>
		<div style="display: none;" id="divOtraMarca">
		<input type="text" class="{$e.q_css_class}" value="{$otraMarca}" size="50" name="otraMarca" id="otraMarca"/> {$smarty.const.LA_BRAND_HERE}</div>   	
	{elseif $e.q_type=="j"}
		<input type="hidden" value="{$e.q_value}" id="hidden_id_{$e.q_css_class}"/>
   		<select name="e_{$e.q_field}" id="id_{$e.q_field}" class="{$e.q_css_class}" onchange="javascript: showEditable(this.options[this.selectedIndex].value);" >
   			<option value=""> --- Seleccione --- </option>
   			{$marcasPorMercado}
		</select>
		<div style="display: none;" id="divOtraMarca">
		<input type="text" class="{$e.q_css_class}" value="{$otraMarca}" size="50" name="otraMarca" id="otraMarca"/> {$smarty.const.LA_BRAND_HERE}</div>
   	{elseif $e.q_type=="p"}

   		<input type="text" name="e_{$e.q_field}" size="7" value="{$e.q_value|replace:".":$decimal}" class="{$e.cssClass}"/> {$set_currency_text}
   	
   	{elseif $e.q_type=="d"}

   		<textarea cols="{$e.q_size}" rows="{$e.q_size_2}" name="e_{$e.q_field}">{$e.q_value}</textarea>
   		
   	{elseif $e.q_type=="c"}
   		{foreach item=opt from=$e.options}
   		<input type="checkbox" name="e_{$e.q_field}[]" id="{$e.q_field}" value="{$opt.value}" {if $opt.selected_value} checked{/if}>
   			{if $opt.$lang} {$opt.$lang|escape}{else}{$opt.text|escape}{/if} <br />
   		{/foreach}

   	{elseif $e.q_type=="s"}
	   	<select name="e_{$e.q_field}" class="txt">
	   	{if $e.q_mand}
	   		<option value=''>--</option>
	   	{else}
	   		<option value='0'>{$smarty.const.LA_EMPTY}</option>
	   	{/if}	
   		{foreach item=opt from=$e.options}
   			<option value="{$opt.value}"{if $opt.selected_value} selected{/if}>{if $opt.$lang} {$opt.$lang|escape}{else}{$opt.text|escape}{/if}</option>
   		{/foreach}
   		</select>
   		
   	{elseif $e.q_type=="r"}
   		
   		{foreach item=opt from=$e.options}
   			<input type="radio" name="e_{$e.q_field}[]" id="{$e.q_field}" value="{$opt.value}" {if $opt.selected_value} checked{/if}>
   			{if $opt.$lang} {$opt.$lang|escape}{else}{$opt.text|escape}{/if} <br />
   		{/foreach}
   		
   		
   	{/if}
   	

   	
   </td>
</tr>

{/foreach} 
  
  <!-- UBICACION -->
  <b></b>
  <tr>
    <td width="30%" valign="top" align="right" style="padding-right: 5px;">
		{$smarty.const.EF_PROVINCIA}</span><span class="red">*</span>
	</td>
    <td width="70%" valign="top">
				<select name="provincia" id="provincia" onchange="cleanLocalidad();">
					<option value=""> --- Provincia --- </option>
				  				{$options_provincia}
				</select>			
				{*<input type="text" name="localidad" id="localidad" size="100" style="width: 300px;" value="{$ad_localidad_str}"/>&nbsp;
				<a onclick="cleanLocalidad();" style="color:#222222; cursor: pointer" title="Buscar otra localidad">X</a>
				<br />
				<div style="font-size: 8pt; color:#222222">
					<strong>Ejemplos: </strong>
					<ul style="list-style-type: circle; list-style-position:inside;">
						<li>Lanus, Buenos A	ires</li>						
					</ul>
				</div>*}
    </td>
  </tr>    
  {*<tr>
  	<td width="30%" valign="top" align="right" style="padding-right: 5px;">
		{$smarty.const.EF_LOCALIDAD}</span>
	</td>
  	<td>
  		<input type="text" name="localidad_name" id="localidad_name" size="100" style="width: 300px;" value="{$ad_localidad_str}"/>
  	</td>
  </tr>*}
  
  
  {if ($admin_area || $ad_id) && $cat_list }

    <tr>
    <td width="30%" valign="top" align="right" style="padding-right: 5px;">Tipo (Categoria)</td>
    <td width="70%" valign="top"><select name='catid' class="txt">
    {$cat_list}
   	</select>
    </td>
  </tr>
  
  {/if}
  

{if $set_expire_days_option==1 && !$ad_id}
  <tr>
  <td width="30%" valign="top">{$smarty.const.LA_RUNDAYS} <font color=red>*</font></td>
  <td width="70%" valign="top"><select name="expire_days" class="txt">
  {$expire_list}
  </select>
  </td>
  </tr>
  {/if}

  
<tr>
<td>
<p><input type='submit' name='submit' class='button' value='{$smarty.const.SUBMIT_BUTTON}'></p>
</td>
<td>
	{if $update_rq!=1}
	<center>
			<div class="recuadroImportante">
				
					{if $paqueteGratis==1}
						{$smarty.const.EF_NOTA_FOTO_GRATIS}
					{else}
						{$smarty.const.EF_NOTA_FOTO_PAGO}
					{/if}	
			</div>
	</center>
	{/if}	
</td>
</tr>
</table>
</form>
{/if}


</td></tr></table>


